package la.bbs558.entity.enums;

import la.bbs558.exception.MsgException;
import la.bbs558.strategy.base.StrategyEnum;
import la.bbs558.util.Objs;
import lombok.Getter;

import java.util.Arrays;
import java.util.List;

@Getter
public enum CaptchaTypeEnum implements StrategyEnum {
    MAIL("邮件", 1),
    MESSAGE("短信", 2),
    GRAPH("图形", 3)
    ;

    private final String desc;
    private final Integer code;

    private final static List<CaptchaTypeEnum> enums = Arrays.asList(values());

    CaptchaTypeEnum(String desc, Integer code) {
        this.desc = desc;
        this.code = code;
    }

    public static CaptchaTypeEnum getByName(String optType){
        for (CaptchaTypeEnum value : enums) {
            if(Objs.equal(value.name(),optType)){
                return value;
            }
        }
        throw new MsgException("不存在此枚举");
    }
}

